package com.manage.competition.service.impl;

import com.manage.competition.entity.SingleLevelOption;
import com.manage.competition.mapper.SingleLevelOptionMapper;
import com.manage.competition.repository.SingleLevelOptionRepository;
import com.manage.competition.service.ISingleOptionService;
import com.manage.competition.util.CurrentUserUtil;
import com.manage.competition.util.SnowflakeUtil;
import com.manage.competition.vo.SingleLevelOptionVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Create with IDEA
 *
 * @Author: gitee.com/KamisamaXX
 * @Date: Create in 23:28 2019/3/29
 * @Description:
 */
@Service
public class SingleOptionServerImpl implements ISingleOptionService{

    @Autowired
    private SingleLevelOptionMapper singleLevelOptionMapper;

    @Autowired
    private SingleLevelOptionRepository singleLevelOptionRepository;

    @Override
    public int insert(SingleLevelOption levelOption) {
        levelOption.setId(SnowflakeUtil.nextId());
        levelOption.setCreateUser(CurrentUserUtil.getCurrentUser().getUsername());
        levelOption.setUpdateUser(CurrentUserUtil.getCurrentUser().getUsername());
        return singleLevelOptionMapper.insert(levelOption);
    }

    @Override
    public List<SingleLevelOptionVo> findBySignupInfo(long id) {
        List<SingleLevelOption> list = singleLevelOptionRepository.findAllBySignupInformationId(id);
        List<SingleLevelOptionVo> res = new ArrayList<>();
        for (SingleLevelOption item:
                list) {
            SingleLevelOptionVo vo = new SingleLevelOptionVo();
            BeanUtils.copyProperties(item,vo);
            res.add(vo);
        }
        return res;
    }

    @Override
    public int deleteOption(long id) {
        return singleLevelOptionMapper.deleteByPrimaryKey(id);
    }
}
